home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
PowerPlant
/
AGA Classes 1.2
/
Sliders
/
LAGAPointedHSlider.cp
< prev
next >
Wrap
Text File
|
1996-06-30
|
18KB
|
614 lines
// ===========================================================================
// LAGAPointedHSlider.cp
// ===========================================================================
// “Apple Grayscale Appearance” compliant pointed horizontal slider control
// Copyright © 1996 Chrisoft (Christophe ANDRES) All rights reserved.
//
// You may use this source code in any application (commercial, shareware, freeware,
// postcardware, etc), but not remove this notice (no need to acknowledge the use of
// this class in the about box)
// You may not sell this source code in any form. This source code may be placed on
// publicly accessable archive sites and source code disks. It may not be placed on
// profit archive sites and source code disks without the permission of the author,
// Christophe ANDRES.
//
// This source code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// If you make any change or improvement on this class, please send the improved/changed
// version to : chrisoft@calva.net or Christophe ANDRES
// 20, rue Prosper Mérimée
// 67100 STRASBOURG
// FRANCE
//
// ===========================================================================
// LAGAPointedHSlider.h <- double-click + Command-D to see class declaration
//
// LAGAPointedHSlider is my implementation of the “Apple Grayscale Appearance for System 7.5”
// horizontal pointed slider control
//
// This class requires LAGASliderBase.cp to be present in your project
// This class requires AGAColors.cp to be present in your project
//
// Version : 1.2
//
// Change History (most recent first, date in US form : mm/dd/yy):
//
// 06/30/96 ca Public release of version 1.2
// 06/27/96 ca Changed checks for disabled state (check on triState_On instead of triState_Off)
// in order that triState_Latent state is drawn as disabled
// 06/04/96 ca Added RegisterClass method to ease registry
// Increased version to 1.2
// 05/16/96 ca class made available by Christophe ANDRES <chrisoft@calva.net>
// (version 1.1)
//
// To Do:
// A subclass that draws also some labels
//
#include "LAGAPointedHSlider.h"
#include "AGAColors.h"
#include <UDrawingState.h>
#include <PP_Types.h>
// begin <06/04/96 ca>
void LAGAPointedHSlider::RegisterClass ()
{
URegistrar::RegisterClass(LAGAPointedHSlider::class_ID, (ClassCreatorFunc)LAGAPointedHSlider::CreateAGAPointedHSliderStream);
}
// end <06/04/96 ca>
LAGAPointedHSlider* LAGAPointedHSlider::CreateAGAPointedHSliderStream (LStream *inStream)
{
return(new LAGAPointedHSlider(inStream));
}
//-------Constructors-------------------------------------------------------------------------------------------------
LAGAPointedHSlider::LAGAPointedHSlider ()
{
mVerticalSlider = false;
mDrawDivisions = false;
}
LAGAPointedHSlider::LAGAPointedHSlider (LStream *inStream) : LAGASliderBase(inStream)
{
unsigned char theBoolean;
inStream->ReadData(&theBoolean, sizeof(unsigned char));
mDrawDivisions = (theBoolean != 0);
}
LAGAPointedHSlider::LAGAPointedHSlider (const LAGAPointedHSlider &inOriginal) : LAGASliderBase(inOriginal)
{
mDrawDivisions = inOriginal.mDrawDivisions;
}
LAGAPointedHSlider::LAGAPointedHSlider (const SPaneInfo &inPaneInfo, MessageT inValueMessage, Boolean inBottomRightPointer,
Boolean inDrawDivisions, Int32 inInitialValue, Int32 inMinValue, Int32 inMaxValue)
: LAGASliderBase(inPaneInfo, inValueMessage, false, inBottomRightPointer, inInitialValue,
inMinValue, inMaxValue)
{
mDrawDivisions = inDrawDivisions;
}
//-------Drawers----------------------------------------------------------------------------------------------------
void LAGAPointedHSlider::DrawIndicator (Boolean inPushed)
{
StColorPenState theState;
Boolean hasColor = ::PaneInColor(this);
Boolean disabled = (mEnabled != triState_On); // <06/27/96 ca>
Rect frame;
theState.Normalize();
CalcLocalFrameRect(frame);
short position = GetIndicatorPosition();
short origin = (mRightBottomPointing ? frame.top : frame.bottom - 1);
short direction = (mRightBottomPointing ? 1 : -1);
::SetRect(&frame, position - 7, (mRightBottomPointing ? origin : origin - 15), position + 7,
(mRightBottomPointing ? origin + 15 : origin));
if (hasColor)
::RGBBackColor(&gAGAColorArray[2]);
::EraseRect(&frame);
if (hasColor && !disabled)
{
Rect r = frame;
if (mRightBottomPointing)
{
r.top++;
r.bottom -= 5;
}
else
r.top += 6;
r.left++;
r.right++;
::RGBBackColor((inPushed ? &gAGAColorArray[8] : &gAGAColorArray[5]));
::EraseRect(&r);
::RGBForeColor((inPushed ? &gAGAColorArray[8] : &gAGAColorArray[5]));
::MoveTo(position + 4, origin + (direction * 10));
::Line(-8, 0);
::Move(1, direction * 1);
::Line(6, 0);
::Move(-1, direction * 1);
::Line(-4, 0);
::Move(1, direction * 1);
::Line(2, 0);
}
if (disabled)
{
if (hasColor)
::RGBForeColor(&gAGAColorArray[8]);
else
::PenPat(&qd.gray);
}
else
::ForeColor(blackColor);
::MoveTo(position - 7, origin + (direction * 1));
::Line(0, direction * 8);
if (!hasColor && disabled)
::PenPat(&qd.black);
::Line(6, direction * 6);
if (!hasColor && disabled)
::PenPat(&qd.gray);
::Line(2, 0);
if (!hasColor && disabled)
::PenPat(&qd.black);
::Line(6, direction * -6);
if (!hasColor && disabled)
::PenPat(&qd.gray);
::Line(0, direction * -8);
::Move(-1, direction * -1);
::Line(-12, 0);
if (hasColor)
{
if (mRightBottomPointing)
{
::RGBForeColor((disabled ? &gAGAColorArray[1] : (inPushed ? &gAGAColorArray[5] : &gAGAColorArray[3])));
::Move(1, 1); ::Line(10, 0);
::Move(-11, 1); ::Line(0, 7);
if (!disabled)
{
::Move(3, -1); ::Line(0, -4);
::Move(2, 0); ::Line(0, 4);
::Move(2, 0); ::Line(0, -4);
}
::RGBForeColor((disabled ? &gAGAColorArray[4] : (inPushed ? &gAGAColorArray[10] : &gAGAColorArray[8])));
::MoveTo(position + 6, origin + 2);
::Line(0, 7);
::Line(-5, 5);
::Line(-2, 0);
::Line(-4, -4);
::RGBForeColor((disabled ? &gAGAColorArray[W] : (inPushed ? &gAGAColorArray[3] : &gAGAColorArray[1])));
::Move(-1, -9); ::Line(0, 0);
if (!disabled)
{
::Move(3, 2); ::Line(0, 0);
::Move(2, 0); ::Line(0, 0);
::Move(2, 0); ::Line(0, 0);
::RGBForeColor((inPushed ? &gAGAColorArray[12] : &gAGAColorArray[10]));
::Move(1, 1); ::Line(0, 5);
::Move(-2, 0); ::Line(0, -5);
::Move(-2, 0); ::Line(0, 5);
}
}
else
{
::RGBForeColor((disabled ? &gAGAColorArray[4] : (inPushed ? &gAGAColorArray[10] : &gAGAColorArray[8])));
::Move(1, -1); ::Line(11, 0);
::Line(0, -8);
::Line(-4, -4);
::RGBForeColor((disabled ? &gAGAColorArray[1] : (inPushed ? &gAGAColorArray[5] : &gAGAColorArray[3])));
::Move(-2, -1); ::Line(0, 0);
::Move(-2, 1); ::Line(-3, 3);
::Move(-1, 2); ::Line(0, 6);
if (!disabled)
{
::Move(3, -2); ::Line(0, -4);
::Move(2, 0); ::Line(0, 4);
::Move(2, 0); ::Line(0, -4);
}
::RGBForeColor((disabled ? &gAGAColorArray[W] : (inPushed ? &gAGAColorArray[3] : &gAGAColorArray[1])));
::MoveTo(position - 1, origin - 14);
::Line(0, 0);
::Move(-5, 5); ::Line(0, 0);
if (!disabled)
{
::Move(3, 0); ::Line(0, 0);
::Move(2, 0); ::Line(0, 0);
::Move(2, 0); ::Line(0, 0);
::RGBForeColor((inPushed ? &gAGAColorArray[12] : &gAGAColorArray[10]));
::Move(1, 1); ::Line(0, 5);
::Move(-2, 0); ::Line(0, -5);
::Move(-2, 0); ::Line(0, 5);
::RGBForeColor((inPushed ? &gAGAColorArray[8] : &gAGAColorArray[5]));
::Move(3, -11); ::Line(0, 0);
}
}
}
else
if (!disabled)
{
::PenPat(&qd.black);
::Move(4, direction * 4);
::Line(0, direction * 5);
::Move(2, 0);
::Line(0, direction * -5);
::Move(2, 0);
::Line(0, direction * 5);
}
}
Int16 LAGAPointedHSlider::FindHotSpot (Point inPoint)
{
Rect frame;
// The only hot spot we know of in a slider is the pointer
GetIndicatorRect(frame);
return(::PtInRect(inPoint, &frame) ? 1 : 0);
}
Boolean LAGAPointedHSlider::PointInHotSpot (Point inPoint, Int16 inHotSpot)
{
Rect frame;
// The only hot spot we know of in a slider is the pointer
GetIndicatorRect(frame);
return(::PtInRect(inPoint, &frame));
}
short LAGAPointedHSlider::GetIndicatorPosition ()
{
Rect frame;
CalcLocalFrameRect(frame);
double size = (frame.right - frame.left) - 22;
double division = size / (double)(mMaxValue - mMinValue);
return(frame.left + 11 + ((mValue - mMinValue) * division));
}
void LAGAPointedHSlider::GetIndicatorRect (Rect &outRect)
{
Rect frame;
CalcLocalFrameRect(frame);
short position = GetIndicatorPosition();
short origin = (mRightBottomPointing ? frame.top : frame.bottom - 1);
::SetRect(&outRect, position - 7, (mRightBottomPointing ? origin : origin - 15), position + 8,
(mRightBottomPointing ? origin + 16 : origin + 1));
}
void LAGAPointedHSlider::InitializeGhost ()
{
Boolean hasColor = ::PaneInColor(this);
Rect r;
LAGASliderBase::InitializeGhost();
mGhostPointer->BeginDrawing();
if (hasColor)
::RGBBackColor(&gAGAColorArray[2]);
::SetRect(&r, 0, 0, 15, 16);
::EraseRect(&r);
short origin = (mRightBottomPointing ? r.top : r.bottom - 1);
short direction = (mRightBottomPointing ? 1 : -1);
if (hasColor)
::RGBForeColor(&gAGAColorArray[7]);
::MoveTo(0, origin + (direction * 1));
::Line(0, direction * 8);
::Line(6, direction * 6);
::Line(2, 0);
::Line(6, direction * -6);
::Line(0, direction * -8);
::Move(-1, direction * -1);
::Line(-12, 0);
::Move(12, direction * 4);
::Line(0, 0);
::Move(0, direction * 4);
::Line(0, 0);
if (hasColor)
{
if (mRightBottomPointing)
{
::RGBForeColor(&gAGAColorArray[5]);
::Move(-1, 0); ::Line(-2, 0);
::Move(0, -4); ::Line(2, 0);
::Move(-3, 1); ::Line(0, 2);
::Move(0, 2); ::Line(0, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(0, -2); ::Line(0, -2);
::Move(-2, 0); ::Line(0, 2);
::Move(0, 2); ::Line(0, 0);
::Move(-2, -1); ::Line(-1, 0);
::Move(0, -4); ::Line(1, 0);
::RGBForeColor(&gAGAColorArray[4]);
::Move(-1, 6); ::Line(4, 4);
::Line(2, 0); ::Line(5, -5);
::Move(0, -2); ::Line(0, -2);
::Move(0, -2); ::Line(0, -1);
::RGBForeColor(&gAGAColorArray[11]);
::Move(1, 2); ::Line(0, 0);
::Move(0, 4); ::Line(0, 0);
::Move(-14, 0); ::Line(0, 0);
::Move(0, -4); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[1]);
::Move(1, -3); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[9]);
::Move(4, 3); ::Line(0, 0);
::Move(0, 4); ::Line(0, 0);
::Move(2, 0); ::Line(0, 0);
::Move(0, -4); ::Line(0, 0);
::Move(2, 0); ::Line(0, 0);
::Move(0, 4); ::Line(0, 0);
::ForeColor(whiteColor);
::Move(-1, -1); ::Line(0, -2);
::Move(0, -2); ::Line(0, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(0, 2); ::Line(0, 2);
::Move(-2, 0); ::Line(0, -2);
::Move(0, -2); ::Line(0, 0);
::Move(-3, 6); ::Line(0, 0);
::Move(0, -2); ::Line(0, -2);
::Move(0, -2); ::Line(0, -1);
::Move(1, -1); ::Line(10, 0);
}
else
{
::RGBForeColor(&gAGAColorArray[5]);
::Move(-1, 0); ::Line(-2, 0);
::Move(0, 4); ::Line(2, 0);
::Move(-3, 1); ::Line(0, 0);
::Move(0, -2); ::Line(0, -2);
::Move(-2, 0); ::Line(0, 2);
::Move(0, 2); ::Line(0, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(0, -2); ::Line(0, -2);
::Move(-2, -1); ::Line(-1, 0);
::Move(0, 4); ::Line(1, 0);
::RGBForeColor(&gAGAColorArray[4]);
::Move(-1, 3); ::Line(11, 0);
::Line(0, -2);
::Move(0, -2); ::Line(0, -2);
::Move(0, -2); ::Line(-4, -4);
::RGBForeColor(&gAGAColorArray[1]);
::Move(-2, -1); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[9]);
::Move(2, 6); ::Line(0, 0);
::Move(0, 4); ::Line(0, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(0, -4); ::Line(0, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(0, 4); ::Line(0, 0);
::RGBForeColor(&gAGAColorArray[11]);
::Move(-5, 0); ::Line(0, 0);
::Move(0, -4); ::Line(0, 0);
::Move(14, 0); ::Line(0, 0);
::Move(0, 4); ::Line(0, 0);
::ForeColor(whiteColor);
::Move(-6, -1); ::Line(0, -2);
::Move(0, -2); ::Line(0, 0);
::Move(-2, 0); ::Line(0, 0);
::Move(0, 2); ::Line(0, 2);
::Move(-2, 0); ::Line(0, -2);
::Move(0, -2); ::Line(0, 0);
::Move(2, -5); ::Line(-5, 5);
::Move(0, 2); ::Line(0, 2);
::Move(0, 2); ::Line(0, 1);
}
}
mGhostPointer->EndDrawing();
// Define a region to draw the pointer nicely if the ghost passes on its top
mGhostMask = ::NewRgn();
::OpenRgn();
::MoveTo(0, origin + (direction * 1));
::Line(0, direction * 8);
::Line(6, direction * 6);
::Line(2, 0);
::Line(6, direction * -6);
::Line(0, direction * -8);
::Line(-1, direction * -1);
::Line(-12, 0);
::Line(-1, direction * 1);
::CloseRgn(mGhostMask);
}
void LAGAPointedHSlider::DrawGhost (Point inPoint)
{
Rect frame;
short position;
if (inPoint.h != mLastPosition.h)
{
Rect indicRect, overStep;
CalcLocalFrameRect(frame);
double size = (frame.right - frame.left) - 22;
double division = size / (double)(mMaxValue - mMinValue);
short MaxPt = frame.left + 11 + ((mMaxValue - mMinValue) * division);
short MinPt = frame.left + 11;
short origin = (mRightBottomPointing ? frame.top : frame.bottom - 1);
if (inPoint.h > MaxPt)
position = MaxPt;
else
if (inPoint.h < MinPt)
position = MinPt;
else
position = inPoint.h;
frame.top = (mRightBottomPointing ? origin : origin - 15);
frame.bottom = frame.top + 16;
frame.left = position - 7;
frame.right = frame.left + 15;
if (!::EmptyRect(&mLastGhost))
{
indicRect = mLastGhost;
StClipRgnState clip;
if (indicRect.left < frame.left)
{
if (indicRect.right > frame.left)
indicRect.right = frame.left;
}
else
{
if (frame.right > indicRect.left)
indicRect.left = frame.right;
}
clip.ClipToIntersection(indicRect);
::RGBBackColor(&gAGAColorArray[2]);
::EraseRect(&mLastGhost);
DrawSlideTrack();
GetIndicatorRect(indicRect);
if (::SectRect(&indicRect, &mLastGhost, &overStep))
DrawIndicator(true);
}
StColorPenState theState;
theState.Normalize();
mGhostPointer->CopyImage(GetMacPort(), frame);
if ((!::EmptyRect(&overStep)) && (mGhostMask != nil))
{
StClipRgnState clip;
::OffsetRgn(mGhostMask, -(*mGhostMask)->rgnBBox.left, -(*mGhostMask)->rgnBBox.top);
::OffsetRgn(mGhostMask, frame.left, frame.top);
RgnHandle theClipRegion = ::NewRgn();
GetIndicatorRect(indicRect);
::RectRgn(theClipRegion, &indicRect);
::DiffRgn(theClipRegion, mGhostMask, theClipRegion);
clip.ClipToIntersectionRgn(theClipRegion);
DrawIndicator(true);
}
mLastGhost = frame;
mLastPosition = inPoint;
}
}
void LAGAPointedHSlider::FinishTrackHotSpot (Point inPoint)
{
Boolean hasColor = ::PaneInColor(this);
Rect frame, indicRect;
short newValue;
CalcLocalFrameRect(frame);
double size = (frame.right - frame.left) - 22;
double division = size / (double)(mMaxValue - mMinValue);
short MaxPt = frame.left + 11 + ((mMaxValue - mMinValue) * division);
short MinPt = frame.left + 11;
if (inPoint.h >= MaxPt)
newValue = mMaxValue;
else
if (inPoint.h <= MinPt)
newValue = mMinValue;
else
{
newValue = ((inPoint.h - MinPt) / division) + mMinValue;
short lowPos = frame.left + 11 + (newValue * division);
short highPos = frame.left + 11 + ((newValue + 1) * division);
if ((inPoint.h - lowPos) > (highPos - inPoint.h))
newValue++;
}
if (newValue != mValue)
{
StClipRgnState clip;
clip.Normalize();
GetIndicatorRect(indicRect);
if (hasColor)
::RGBBackColor(&gAGAColorArray[2]);
::EraseRect(&indicRect);
::EraseRect(&mLastGhost);
DrawSlideTrack();
// Update our control value and Broadcast it
SetValue(newValue);
}
else
{
if (hasColor)
::RGBBackColor(&gAGAColorArray[2]);
::EraseRect(&mLastGhost);
DrawSlideTrack();
}
// We dont redraw the pointer here, because it will anyway be redrawn in the unpressed state
// in the method LAGASliderBase::HotSpotResult
}
void LAGAPointedHSlider::DrawLabels ()
{
if (mDrawDivisions)
{
StColorPenState theState;
Boolean hasColor = ::PaneInColor(this);
Boolean disabled = (mEnabled != triState_On); // <06/27/96 ca>
Rect frame;
CalcLocalFrameRect(frame);
double size = (frame.right - frame.left) - 22;
double division = size / (double)(mMaxValue - mMinValue);
short step = 1;
if (division < 4)
step = 2;
short origin = (mRightBottomPointing ? frame.top : frame.bottom - 1);
short direction = (mRightBottomPointing ? 1 : -1);
short position;
for (int i = mMinValue; i <= mMaxValue; i += step)
{
position = frame.left + 11 + ((i - mMinValue) * division);
if (hasColor)
::RGBForeColor((disabled ? &gAGAColorArray[8] : &gAGAColorArray[B]));
else
if (disabled)
::PenPat(&qd.gray);
::MoveTo(position, origin + (direction * 17));
::Line(0, direction * 5);
if (hasColor)
{
if (!mRightBottomPointing)
::Move(0, 5);
::RGBForeColor((disabled ? &gAGAColorArray[4] : &gAGAColorArray[7]));
::Move(0, 1);
::Line(1, 0);
::Line(0, -6);
::ForeColor(whiteColor);
::Move(-1, -1);
::Line(-1, 0);
::Line(0, 6);
}
}
}
}